package com.vv.tools.modules.auth.handler;


import com.vv.tools.common.message.Result;
import com.vv.tools.common.message.ResultEnum;
import com.vv.tools.common.util.ResponseUtil;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

/**
 * @author wen.li
 * 没权限访问
 * 用于处理用户尝试访问受保护资源但权限不足的情况
 */
@Component("loginAccessDefineHandler")
public class LoginAccessDefineHandler implements AccessDeniedHandler {


    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) {
        ResponseUtil.of(response, Result.fail(ResultEnum.AUTH_LOGIN_ACCESS_DEFINE));
    }
}
